package com.cn.kehong.controller;


import com.alibaba.fastjson.JSONObject;
import com.cn.kehong.api.*;
import com.cn.kehong.domain.*;
import com.cn.kehong.utils.CommonUtil;
import com.cn.kehong.utils.JsonResponse;
import com.cn.kehong.utils.QueryForm;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/physicalChemical")
public class PhysicalChemicalController {

    @Autowired
    private IPhysicalChemicalService iphysicalChemicalService;

    @Autowired
    private IPhysicalChemicalGranularityService iPhysicalChemicalGranularityService;

    @Autowired
    private ISysItemService sysItemService;
    @Autowired
    private IPhysicalChemicalWaterService iPhysicalChemicalWaterService;

    @Autowired
    private IProductPackageService iProductPackageService;
    //水分初始化列表页面
    @RequestMapping("/getPhysicalChemical/{frontToken}")
    @ResponseBody
    public JsonResponse<List<PhysicalChemicalVo>> getPhysicalChemical(@PathVariable(value = "frontToken", required = true) String frontToken, QueryForm queryForm) throws Exception {
        JsonResponse<List<PhysicalChemicalVo>> response = new JsonResponse<>();
        List<PhysicalChemicalVo> physicalChemicals = iphysicalChemicalService.getPhysicalChemicalsList(queryForm);
        response.setResult(physicalChemicals);
        response.setSuccess(true);
        return response;
    }


    //粒度初始化列表页面
    @RequestMapping("/getPhysicalGranularity/{frontToken}")
    @ResponseBody
    public JsonResponse<List<PhysicalChemicalVo>> getPhysicalGranularity(@PathVariable(value = "frontToken", required = true) String frontToken, QueryForm queryForm) throws Exception {
        JsonResponse<List<PhysicalChemicalVo>> response = new JsonResponse<>();
        List<PhysicalChemicalVo> physicalChemicals = iphysicalChemicalService.getPhysicalGranularity(queryForm);
        response.setResult(physicalChemicals);
        response.setSuccess(true);
        return response;
    }

    //取消接口
    @RequestMapping("/cancle/{frontToken}")
    @ResponseBody
    public JsonResponse<String> cancle(@RequestBody QueryForm queryForm,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = iphysicalChemicalService.cancle(queryForm);
        return CommonUtil.getResponseData(response,result);
    }


    //粒度录入接口
    @RequestMapping("/addPhysicalGranularity/{frontToken}")
    @ResponseBody
    public JsonResponse<String> addPhysicalGranularity(@RequestBody PhysicaChemicalGranularity physicaChemicalGranularity, @PathVariable(value =  "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = iPhysicalChemicalGranularityService.addPhysicalGranularity(physicaChemicalGranularity);
        return CommonUtil.getResponseData(response,result);
    }


    //水分红色的指标数量
    @RequestMapping("/getWaterCount/{frontToken}")
    @ResponseBody
    public JsonResponse<List<PhysicalChemicalVo>> getWaterCount(@PathVariable(value = "frontToken", required = true) String frontToken, QueryForm queryForm) throws Exception {
        JsonResponse<List<PhysicalChemicalVo>> response = new JsonResponse<>();
        List<PhysicalChemicalVo> physicalChemicals = iphysicalChemicalService.getPhysicalChemicalCount(queryForm);
        response.setResult(physicalChemicals);
        response.setSuccess(true);
        return response;
    }

    //粒度红色的指标数量
    @RequestMapping("/getGranularityCount/{frontToken}")
    @ResponseBody
    public JsonResponse<List<PhysicalChemicalVo>> getGranularityCount(@PathVariable(value = "frontToken", required = true) String frontToken, QueryForm queryForm) throws Exception {
        JsonResponse<List<PhysicalChemicalVo>> response = new JsonResponse<>();
        List<PhysicalChemicalVo> physicalChemicals = iphysicalChemicalService.getGranularityCount(queryForm);
        response.setResult(physicalChemicals);
        response.setSuccess(true);
        return response;
    }

    //粒度判断是否存在
    @RequestMapping("/getGranularityHaving/{frontToken}")
    @ResponseBody
    public JsonResponse<List<PhysicalChemicalVo>> getGranularityHaving(@PathVariable(value = "frontToken", required = true) String frontToken, QueryForm queryForm) throws Exception {
        JsonResponse<List<PhysicalChemicalVo>> response = new JsonResponse<>();
        List<PhysicalChemicalVo> physicalChemicals = iphysicalChemicalService.getGranularityHaving(queryForm);
        response.setResult(physicalChemicals);
        response.setSuccess(true);
        return response;
    }
    //水分判断是否存在
    @RequestMapping("/getWaterHaving/{frontToken}")
    @ResponseBody
    public JsonResponse<List<PhysicalChemicalVo>> getWaterHaving(@PathVariable(value = "frontToken", required = true) String frontToken, QueryForm queryForm) throws Exception {
        JsonResponse<List<PhysicalChemicalVo>> response = new JsonResponse<>();
        List<PhysicalChemicalVo> physicalChemicals = iphysicalChemicalService.getWaterHaving(queryForm);
        response.setResult(physicalChemicals);
        response.setSuccess(true);
        return response;
    }

    @RequestMapping("/getPhysicalChemicalByRelateId/{frontToken}")
    @ResponseBody
    public JsonResponse<List<PhysicalChemical>> getPhysicalChemicalByRelateId(@PathVariable(value = "frontToken", required = true) String frontToken, String relateId) throws Exception {
        JsonResponse<List<PhysicalChemical>> response = new JsonResponse<>();
        List<PhysicalChemical> physicalChemicals = iphysicalChemicalService.getPhysicalChemicalByRelateId(relateId);
        response.setResult(physicalChemicals);
        response.setSuccess(true);
        return response;
    }


    @RequestMapping("/addBatchWater/{frontToken}")
    @ResponseBody
    public JsonResponse<String> addBatchWater(@RequestBody List<PhysicaChemicalWater> physicaChemicalWaters,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = iPhysicalChemicalWaterService.addBatchWater(physicaChemicalWaters);
        return CommonUtil.getResponseData(response,result);
    }

    @RequestMapping("/addPhysicalChemical/{frontToken}")
    @ResponseBody
    public JsonResponse<String> addPhysicalChemical( PhysicalChemical physicalChemical,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = iphysicalChemicalService.addPhysicalChemical(physicalChemical);
        return CommonUtil.getResponseData(response,result);
    }


    //线边送检记录
    @RequestMapping("/getLineInspectionByApp")
    @ResponseBody
    public JsonResponse<Map<String,Object>> getLineInspectionByApp(@RequestBody QueryForm queryForm) throws Exception {
        JsonResponse<Map<String,Object>> response = new JsonResponse<Map<String,Object>>();
        Map<String,Object>  lineInspectionByApp = iphysicalChemicalService.getLineInspectionByApp(queryForm);
        response.setResult(lineInspectionByApp);
        response.setSuccess(true);
        return response;
    }

    //理化检测新增app端
    @RequestMapping("/addPhysicalChemicalByApp")
    @ResponseBody
    public JsonResponse<String> addPhysicalChemicalByApp(@RequestBody PhysicalChemical physicalChemical) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = iphysicalChemicalService.addPhysicalChemicalByApp(physicalChemical);
        return CommonUtil.getResponseData(response,result);
    }

    @ResponseBody
    @RequestMapping("/getMgItemListByApp")
    public JsonResponse<List<SysItem>> getMgItemList(@RequestBody QueryForm queryForm) throws Exception {
        JsonResponse<List<SysItem>> response = new JsonResponse<List<SysItem>>();
        List<SysItem> mgItems = sysItemService.getMgItemList(queryForm);
        response.setResult(mgItems);
        response.setSuccess(true);
        return response;
    }


    @ResponseBody
    @RequestMapping("/getPhysicalChemicalDetailByApp")
    public JsonResponse<List<PhysicalChemicalVo>> getPhysicalChemicalDetailByApp(@RequestBody QueryForm queryForm) throws Exception {
        JsonResponse<List<PhysicalChemicalVo>> response = new JsonResponse<List<PhysicalChemicalVo>>();
        List<PhysicalChemicalVo> physicalChemicals = iphysicalChemicalService.getPhysicalChemicalDetailByApp(queryForm);
        response.setResult(physicalChemicals);
        response.setSuccess(true);
        return response;
    }

    //扫码获取包装信息
    @RequestMapping("/getBzDetailCode")
    @ResponseBody
    public JsonResponse<Map<String,Object>> getBzDetailCode(String qrCode) throws Exception {
        JsonResponse<Map<String,Object> > response = new JsonResponse<Map<String,Object> >();
        Map<String,Object> result = iProductPackageService.getBzDetailCode(qrCode);
        response.setResult(result);
        String errorMsg = (String) result.get("errorMsg");
        response.setSuccess(StringUtils.isEmpty(errorMsg)?true:false);
        return  response;
    }


    @ResponseBody
    @RequestMapping("/redriving/{frontToken}")
    public JsonResponse<String> redriving(@RequestBody PhysicalChemical physicalChemical, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = iphysicalChemicalService.redriving(physicalChemical);
        return CommonUtil.getResponseData(response,result);
    }


    //主页其他动态
    @RequestMapping("/getOtherToday/{frontToken}")
    @ResponseBody
    public JsonResponse<Map<String,Object>> getOtherToday(@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<Map<String,Object>> response = new JsonResponse<Map<String,Object>>();
        Map<String,Object>  counts = iphysicalChemicalService.getOtherToday();
        response.setResult(counts);
        response.setSuccess(true);
        return response;
    }

}


